/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.hotel.test.service.persistence;

import com.hotel.test.NoSuchHotelException;
import com.hotel.test.model.Hotel;
import com.hotel.test.model.impl.HotelImpl;
import com.hotel.test.model.impl.HotelModelImpl;

import com.liferay.portal.NoSuchModelException;
import com.liferay.portal.kernel.bean.BeanReference;
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
import com.liferay.portal.kernel.dao.jdbc.RowMapper;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.SQLQuery;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.service.persistence.BatchSessionUtil;
import com.liferay.portal.service.persistence.ResourcePersistence;
import com.liferay.portal.service.persistence.UserPersistence;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * The persistence implementation for the hotel service.
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author Vien-IT
 * @see HotelPersistence
 * @see HotelUtil
 * @generated
 */
public class HotelPersistenceImpl extends BasePersistenceImpl<Hotel>
	implements HotelPersistence {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. Always use {@link HotelUtil} to access the hotel persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
	 */
	public static final String FINDER_CLASS_NAME_ENTITY = HotelImpl.class.getName();
	public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List1";
	public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List2";
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_HOTELNAME =
		new FinderPath(HotelModelImpl.ENTITY_CACHE_ENABLED,
			HotelModelImpl.FINDER_CACHE_ENABLED, HotelImpl.class,
			FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByHotelName",
			new String[] {
				String.class.getName(),
				
			"java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_HOTELNAME =
		new FinderPath(HotelModelImpl.ENTITY_CACHE_ENABLED,
			HotelModelImpl.FINDER_CACHE_ENABLED, HotelImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByHotelName",
			new String[] { String.class.getName() },
			HotelModelImpl.HOTELNAME_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_HOTELNAME = new FinderPath(HotelModelImpl.ENTITY_CACHE_ENABLED,
			HotelModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByHotelName",
			new String[] { String.class.getName() });
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(HotelModelImpl.ENTITY_CACHE_ENABLED,
			HotelModelImpl.FINDER_CACHE_ENABLED, HotelImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(HotelModelImpl.ENTITY_CACHE_ENABLED,
			HotelModelImpl.FINDER_CACHE_ENABLED, HotelImpl.class,
			FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(HotelModelImpl.ENTITY_CACHE_ENABLED,
			HotelModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);

	/**
	 * Caches the hotel in the entity cache if it is enabled.
	 *
	 * @param hotel the hotel
	 */
	public void cacheResult(Hotel hotel) {
		EntityCacheUtil.putResult(HotelModelImpl.ENTITY_CACHE_ENABLED,
			HotelImpl.class, hotel.getPrimaryKey(), hotel);

		hotel.resetOriginalValues();
	}

	/**
	 * Caches the hotels in the entity cache if it is enabled.
	 *
	 * @param hotels the hotels
	 */
	public void cacheResult(List<Hotel> hotels) {
		for (Hotel hotel : hotels) {
			if (EntityCacheUtil.getResult(HotelModelImpl.ENTITY_CACHE_ENABLED,
						HotelImpl.class, hotel.getPrimaryKey()) == null) {
				cacheResult(hotel);
			}
			else {
				hotel.resetOriginalValues();
			}
		}
	}

	/**
	 * Clears the cache for all hotels.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache() {
		if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
			CacheRegistryUtil.clear(HotelImpl.class.getName());
		}

		EntityCacheUtil.clearCache(HotelImpl.class.getName());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	/**
	 * Clears the cache for the hotel.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache(Hotel hotel) {
		EntityCacheUtil.removeResult(HotelModelImpl.ENTITY_CACHE_ENABLED,
			HotelImpl.class, hotel.getPrimaryKey());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	@Override
	public void clearCache(List<Hotel> hotels) {
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		for (Hotel hotel : hotels) {
			EntityCacheUtil.removeResult(HotelModelImpl.ENTITY_CACHE_ENABLED,
				HotelImpl.class, hotel.getPrimaryKey());
		}
	}

	/**
	 * Creates a new hotel with the primary key. Does not add the hotel to the database.
	 *
	 * @param hotelId the primary key for the new hotel
	 * @return the new hotel
	 */
	public Hotel create(long hotelId) {
		Hotel hotel = new HotelImpl();

		hotel.setNew(true);
		hotel.setPrimaryKey(hotelId);

		return hotel;
	}

	/**
	 * Removes the hotel with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param hotelId the primary key of the hotel
	 * @return the hotel that was removed
	 * @throws com.hotel.test.NoSuchHotelException if a hotel with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Hotel remove(long hotelId)
		throws NoSuchHotelException, SystemException {
		return remove(Long.valueOf(hotelId));
	}

	/**
	 * Removes the hotel with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param primaryKey the primary key of the hotel
	 * @return the hotel that was removed
	 * @throws com.hotel.test.NoSuchHotelException if a hotel with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public Hotel remove(Serializable primaryKey)
		throws NoSuchHotelException, SystemException {
		Session session = null;

		try {
			session = openSession();

			Hotel hotel = (Hotel)session.get(HotelImpl.class, primaryKey);

			if (hotel == null) {
				if (_log.isWarnEnabled()) {
					_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
				}

				throw new NoSuchHotelException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
					primaryKey);
			}

			return remove(hotel);
		}
		catch (NoSuchHotelException nsee) {
			throw nsee;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	@Override
	protected Hotel removeImpl(Hotel hotel) throws SystemException {
		hotel = toUnwrappedModel(hotel);

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.delete(session, hotel);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		clearCache(hotel);

		return hotel;
	}

	@Override
	public Hotel updateImpl(com.hotel.test.model.Hotel hotel, boolean merge)
		throws SystemException {
		hotel = toUnwrappedModel(hotel);

		boolean isNew = hotel.isNew();

		HotelModelImpl hotelModelImpl = (HotelModelImpl)hotel;

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.update(session, hotel, merge);

			hotel.setNew(false);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

		if (isNew || !HotelModelImpl.COLUMN_BITMASK_ENABLED) {
			FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
		}

		else {
			if ((hotelModelImpl.getColumnBitmask() &
					FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_HOTELNAME.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						hotelModelImpl.getOriginalHotelName()
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_HOTELNAME,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_HOTELNAME,
					args);

				args = new Object[] { hotelModelImpl.getHotelName() };

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_HOTELNAME,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_HOTELNAME,
					args);
			}
		}

		EntityCacheUtil.putResult(HotelModelImpl.ENTITY_CACHE_ENABLED,
			HotelImpl.class, hotel.getPrimaryKey(), hotel);

		return hotel;
	}

	protected Hotel toUnwrappedModel(Hotel hotel) {
		if (hotel instanceof HotelImpl) {
			return hotel;
		}

		HotelImpl hotelImpl = new HotelImpl();

		hotelImpl.setNew(hotel.isNew());
		hotelImpl.setPrimaryKey(hotel.getPrimaryKey());

		hotelImpl.setHotelId(hotel.getHotelId());
		hotelImpl.setUserId(hotel.getUserId());
		hotelImpl.setUserName(hotel.getUserName());
		hotelImpl.setCreateDate(hotel.getCreateDate());
		hotelImpl.setModifiedDate(hotel.getModifiedDate());
		hotelImpl.setLocalId(hotel.getLocalId());
		hotelImpl.setHotelName(hotel.getHotelName());
		hotelImpl.setQuality(hotel.getQuality());
		hotelImpl.setIntroduce(hotel.getIntroduce());
		hotelImpl.setImage(hotel.getImage());
		hotelImpl.setAddress(hotel.getAddress());
		hotelImpl.setEmail(hotel.getEmail());
		hotelImpl.setPhone(hotel.getPhone());

		return hotelImpl;
	}

	/**
	 * Returns the hotel with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
	 *
	 * @param primaryKey the primary key of the hotel
	 * @return the hotel
	 * @throws com.liferay.portal.NoSuchModelException if a hotel with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public Hotel findByPrimaryKey(Serializable primaryKey)
		throws NoSuchModelException, SystemException {
		return findByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the hotel with the primary key or throws a {@link com.hotel.test.NoSuchHotelException} if it could not be found.
	 *
	 * @param hotelId the primary key of the hotel
	 * @return the hotel
	 * @throws com.hotel.test.NoSuchHotelException if a hotel with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Hotel findByPrimaryKey(long hotelId)
		throws NoSuchHotelException, SystemException {
		Hotel hotel = fetchByPrimaryKey(hotelId);

		if (hotel == null) {
			if (_log.isWarnEnabled()) {
				_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + hotelId);
			}

			throw new NoSuchHotelException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
				hotelId);
		}

		return hotel;
	}

	/**
	 * Returns the hotel with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param primaryKey the primary key of the hotel
	 * @return the hotel, or <code>null</code> if a hotel with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public Hotel fetchByPrimaryKey(Serializable primaryKey)
		throws SystemException {
		return fetchByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the hotel with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param hotelId the primary key of the hotel
	 * @return the hotel, or <code>null</code> if a hotel with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Hotel fetchByPrimaryKey(long hotelId) throws SystemException {
		Hotel hotel = (Hotel)EntityCacheUtil.getResult(HotelModelImpl.ENTITY_CACHE_ENABLED,
				HotelImpl.class, hotelId);

		if (hotel == _nullHotel) {
			return null;
		}

		if (hotel == null) {
			Session session = null;

			boolean hasException = false;

			try {
				session = openSession();

				hotel = (Hotel)session.get(HotelImpl.class,
						Long.valueOf(hotelId));
			}
			catch (Exception e) {
				hasException = true;

				throw processException(e);
			}
			finally {
				if (hotel != null) {
					cacheResult(hotel);
				}
				else if (!hasException) {
					EntityCacheUtil.putResult(HotelModelImpl.ENTITY_CACHE_ENABLED,
						HotelImpl.class, hotelId, _nullHotel);
				}

				closeSession(session);
			}
		}

		return hotel;
	}

	/**
	 * Returns all the hotels where hotelName = &#63;.
	 *
	 * @param hotelName the hotel name
	 * @return the matching hotels
	 * @throws SystemException if a system exception occurred
	 */
	public List<Hotel> findByHotelName(String hotelName)
		throws SystemException {
		return findByHotelName(hotelName, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
			null);
	}

	/**
	 * Returns a range of all the hotels where hotelName = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param hotelName the hotel name
	 * @param start the lower bound of the range of hotels
	 * @param end the upper bound of the range of hotels (not inclusive)
	 * @return the range of matching hotels
	 * @throws SystemException if a system exception occurred
	 */
	public List<Hotel> findByHotelName(String hotelName, int start, int end)
		throws SystemException {
		return findByHotelName(hotelName, start, end, null);
	}

	/**
	 * Returns an ordered range of all the hotels where hotelName = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param hotelName the hotel name
	 * @param start the lower bound of the range of hotels
	 * @param end the upper bound of the range of hotels (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of matching hotels
	 * @throws SystemException if a system exception occurred
	 */
	public List<Hotel> findByHotelName(String hotelName, int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = null;

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_HOTELNAME;
			finderArgs = new Object[] { hotelName };
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_HOTELNAME;
			finderArgs = new Object[] { hotelName, start, end, orderByComparator };
		}

		List<Hotel> list = (List<Hotel>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;

			if (orderByComparator != null) {
				query = new StringBundler(3 +
						(orderByComparator.getOrderByFields().length * 3));
			}
			else {
				query = new StringBundler(3);
			}

			query.append(_SQL_SELECT_HOTEL_WHERE);

			if (hotelName == null) {
				query.append(_FINDER_COLUMN_HOTELNAME_HOTELNAME_1);
			}
			else {
				if (hotelName.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_HOTELNAME_HOTELNAME_3);
				}
				else {
					query.append(_FINDER_COLUMN_HOTELNAME_HOTELNAME_2);
				}
			}

			if (orderByComparator != null) {
				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);
			}

			else {
				query.append(HotelModelImpl.ORDER_BY_JPQL);
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (hotelName != null) {
					qPos.add(hotelName);
				}

				list = (List<Hotel>)QueryUtil.list(q, getDialect(), start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Returns the first hotel in the ordered set where hotelName = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param hotelName the hotel name
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the first matching hotel
	 * @throws com.hotel.test.NoSuchHotelException if a matching hotel could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Hotel findByHotelName_First(String hotelName,
		OrderByComparator orderByComparator)
		throws NoSuchHotelException, SystemException {
		List<Hotel> list = findByHotelName(hotelName, 0, 1, orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(4);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("hotelName=");
			msg.append(hotelName);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchHotelException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Returns the last hotel in the ordered set where hotelName = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param hotelName the hotel name
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the last matching hotel
	 * @throws com.hotel.test.NoSuchHotelException if a matching hotel could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Hotel findByHotelName_Last(String hotelName,
		OrderByComparator orderByComparator)
		throws NoSuchHotelException, SystemException {
		int count = countByHotelName(hotelName);

		List<Hotel> list = findByHotelName(hotelName, count - 1, count,
				orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(4);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("hotelName=");
			msg.append(hotelName);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchHotelException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Returns the hotels before and after the current hotel in the ordered set where hotelName = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param hotelId the primary key of the current hotel
	 * @param hotelName the hotel name
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the previous, current, and next hotel
	 * @throws com.hotel.test.NoSuchHotelException if a hotel with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Hotel[] findByHotelName_PrevAndNext(long hotelId, String hotelName,
		OrderByComparator orderByComparator)
		throws NoSuchHotelException, SystemException {
		Hotel hotel = findByPrimaryKey(hotelId);

		Session session = null;

		try {
			session = openSession();

			Hotel[] array = new HotelImpl[3];

			array[0] = getByHotelName_PrevAndNext(session, hotel, hotelName,
					orderByComparator, true);

			array[1] = hotel;

			array[2] = getByHotelName_PrevAndNext(session, hotel, hotelName,
					orderByComparator, false);

			return array;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	protected Hotel getByHotelName_PrevAndNext(Session session, Hotel hotel,
		String hotelName, OrderByComparator orderByComparator, boolean previous) {
		StringBundler query = null;

		if (orderByComparator != null) {
			query = new StringBundler(6 +
					(orderByComparator.getOrderByFields().length * 6));
		}
		else {
			query = new StringBundler(3);
		}

		query.append(_SQL_SELECT_HOTEL_WHERE);

		if (hotelName == null) {
			query.append(_FINDER_COLUMN_HOTELNAME_HOTELNAME_1);
		}
		else {
			if (hotelName.equals(StringPool.BLANK)) {
				query.append(_FINDER_COLUMN_HOTELNAME_HOTELNAME_3);
			}
			else {
				query.append(_FINDER_COLUMN_HOTELNAME_HOTELNAME_2);
			}
		}

		if (orderByComparator != null) {
			String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

			if (orderByConditionFields.length > 0) {
				query.append(WHERE_AND);
			}

			for (int i = 0; i < orderByConditionFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByConditionFields[i]);

				if ((i + 1) < orderByConditionFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN_HAS_NEXT);
					}
					else {
						query.append(WHERE_LESSER_THAN_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN);
					}
					else {
						query.append(WHERE_LESSER_THAN);
					}
				}
			}

			query.append(ORDER_BY_CLAUSE);

			String[] orderByFields = orderByComparator.getOrderByFields();

			for (int i = 0; i < orderByFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByFields[i]);

				if ((i + 1) < orderByFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC_HAS_NEXT);
					}
					else {
						query.append(ORDER_BY_DESC_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC);
					}
					else {
						query.append(ORDER_BY_DESC);
					}
				}
			}
		}

		else {
			query.append(HotelModelImpl.ORDER_BY_JPQL);
		}

		String sql = query.toString();

		Query q = session.createQuery(sql);

		q.setFirstResult(0);
		q.setMaxResults(2);

		QueryPos qPos = QueryPos.getInstance(q);

		if (hotelName != null) {
			qPos.add(hotelName);
		}

		if (orderByComparator != null) {
			Object[] values = orderByComparator.getOrderByConditionValues(hotel);

			for (Object value : values) {
				qPos.add(value);
			}
		}

		List<Hotel> list = q.list();

		if (list.size() == 2) {
			return list.get(1);
		}
		else {
			return null;
		}
	}

	/**
	 * Returns all the hotels.
	 *
	 * @return the hotels
	 * @throws SystemException if a system exception occurred
	 */
	public List<Hotel> findAll() throws SystemException {
		return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the hotels.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of hotels
	 * @param end the upper bound of the range of hotels (not inclusive)
	 * @return the range of hotels
	 * @throws SystemException if a system exception occurred
	 */
	public List<Hotel> findAll(int start, int end) throws SystemException {
		return findAll(start, end, null);
	}

	/**
	 * Returns an ordered range of all the hotels.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of hotels
	 * @param end the upper bound of the range of hotels (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of hotels
	 * @throws SystemException if a system exception occurred
	 */
	public List<Hotel> findAll(int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = new Object[] { start, end, orderByComparator };

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
			finderArgs = FINDER_ARGS_EMPTY;
		}
		else {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
			finderArgs = new Object[] { start, end, orderByComparator };
		}

		List<Hotel> list = (List<Hotel>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;
			String sql = null;

			if (orderByComparator != null) {
				query = new StringBundler(2 +
						(orderByComparator.getOrderByFields().length * 3));

				query.append(_SQL_SELECT_HOTEL);

				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);

				sql = query.toString();
			}
			else {
				sql = _SQL_SELECT_HOTEL.concat(HotelModelImpl.ORDER_BY_JPQL);
			}

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				if (orderByComparator == null) {
					list = (List<Hotel>)QueryUtil.list(q, getDialect(), start,
							end, false);

					Collections.sort(list);
				}
				else {
					list = (List<Hotel>)QueryUtil.list(q, getDialect(), start,
							end);
				}
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Removes all the hotels where hotelName = &#63; from the database.
	 *
	 * @param hotelName the hotel name
	 * @throws SystemException if a system exception occurred
	 */
	public void removeByHotelName(String hotelName) throws SystemException {
		for (Hotel hotel : findByHotelName(hotelName)) {
			remove(hotel);
		}
	}

	/**
	 * Removes all the hotels from the database.
	 *
	 * @throws SystemException if a system exception occurred
	 */
	public void removeAll() throws SystemException {
		for (Hotel hotel : findAll()) {
			remove(hotel);
		}
	}

	/**
	 * Returns the number of hotels where hotelName = &#63;.
	 *
	 * @param hotelName the hotel name
	 * @return the number of matching hotels
	 * @throws SystemException if a system exception occurred
	 */
	public int countByHotelName(String hotelName) throws SystemException {
		Object[] finderArgs = new Object[] { hotelName };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_HOTELNAME,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(2);

			query.append(_SQL_COUNT_HOTEL_WHERE);

			if (hotelName == null) {
				query.append(_FINDER_COLUMN_HOTELNAME_HOTELNAME_1);
			}
			else {
				if (hotelName.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_HOTELNAME_HOTELNAME_3);
				}
				else {
					query.append(_FINDER_COLUMN_HOTELNAME_HOTELNAME_2);
				}
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (hotelName != null) {
					qPos.add(hotelName);
				}

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_HOTELNAME,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of hotels.
	 *
	 * @return the number of hotels
	 * @throws SystemException if a system exception occurred
	 */
	public int countAll() throws SystemException {
		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
				FINDER_ARGS_EMPTY, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(_SQL_COUNT_HOTEL);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
					FINDER_ARGS_EMPTY, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns all the rom types associated with the hotel.
	 *
	 * @param pk the primary key of the hotel
	 * @return the rom types associated with the hotel
	 * @throws SystemException if a system exception occurred
	 */
	public List<com.hotel.test.model.RomType> getRomTypes(long pk)
		throws SystemException {
		return getRomTypes(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
	}

	/**
	 * Returns a range of all the rom types associated with the hotel.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param pk the primary key of the hotel
	 * @param start the lower bound of the range of hotels
	 * @param end the upper bound of the range of hotels (not inclusive)
	 * @return the range of rom types associated with the hotel
	 * @throws SystemException if a system exception occurred
	 */
	public List<com.hotel.test.model.RomType> getRomTypes(long pk, int start,
		int end) throws SystemException {
		return getRomTypes(pk, start, end, null);
	}

	public static final FinderPath FINDER_PATH_GET_ROMTYPES = new FinderPath(com.hotel.test.model.impl.RomTypeModelImpl.ENTITY_CACHE_ENABLED,
			com.hotel.test.model.impl.RomTypeModelImpl.FINDER_CACHE_ENABLED,
			com.hotel.test.model.impl.RomTypeImpl.class,
			com.hotel.test.service.persistence.RomTypePersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"getRomTypes",
			new String[] {
				Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});

	/**
	 * Returns an ordered range of all the rom types associated with the hotel.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param pk the primary key of the hotel
	 * @param start the lower bound of the range of hotels
	 * @param end the upper bound of the range of hotels (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of rom types associated with the hotel
	 * @throws SystemException if a system exception occurred
	 */
	public List<com.hotel.test.model.RomType> getRomTypes(long pk, int start,
		int end, OrderByComparator orderByComparator) throws SystemException {
		Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };

		List<com.hotel.test.model.RomType> list = (List<com.hotel.test.model.RomType>)FinderCacheUtil.getResult(FINDER_PATH_GET_ROMTYPES,
				finderArgs, this);

		if (list == null) {
			Session session = null;

			try {
				session = openSession();

				String sql = null;

				if (orderByComparator != null) {
					sql = _SQL_GETROMTYPES.concat(ORDER_BY_CLAUSE)
										  .concat(orderByComparator.getOrderBy());
				}
				else {
					sql = _SQL_GETROMTYPES.concat(com.hotel.test.model.impl.RomTypeModelImpl.ORDER_BY_SQL);
				}

				SQLQuery q = session.createSQLQuery(sql);

				q.addEntity("HT_RomType",
					com.hotel.test.model.impl.RomTypeImpl.class);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(pk);

				list = (List<com.hotel.test.model.RomType>)QueryUtil.list(q,
						getDialect(), start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_GET_ROMTYPES,
						finderArgs);
				}
				else {
					romTypePersistence.cacheResult(list);

					FinderCacheUtil.putResult(FINDER_PATH_GET_ROMTYPES,
						finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	public static final FinderPath FINDER_PATH_GET_ROMTYPES_SIZE = new FinderPath(com.hotel.test.model.impl.RomTypeModelImpl.ENTITY_CACHE_ENABLED,
			com.hotel.test.model.impl.RomTypeModelImpl.FINDER_CACHE_ENABLED,
			com.hotel.test.model.impl.RomTypeImpl.class,
			com.hotel.test.service.persistence.RomTypePersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"getRomTypesSize", new String[] { Long.class.getName() });

	/**
	 * Returns the number of rom types associated with the hotel.
	 *
	 * @param pk the primary key of the hotel
	 * @return the number of rom types associated with the hotel
	 * @throws SystemException if a system exception occurred
	 */
	public int getRomTypesSize(long pk) throws SystemException {
		Object[] finderArgs = new Object[] { pk };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ROMTYPES_SIZE,
				finderArgs, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				SQLQuery q = session.createSQLQuery(_SQL_GETROMTYPESSIZE);

				q.addScalar(COUNT_COLUMN_NAME,
					com.liferay.portal.kernel.dao.orm.Type.LONG);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(pk);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_GET_ROMTYPES_SIZE,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	public static final FinderPath FINDER_PATH_CONTAINS_ROMTYPE = new FinderPath(com.hotel.test.model.impl.RomTypeModelImpl.ENTITY_CACHE_ENABLED,
			com.hotel.test.model.impl.RomTypeModelImpl.FINDER_CACHE_ENABLED,
			com.hotel.test.model.impl.RomTypeImpl.class,
			com.hotel.test.service.persistence.RomTypePersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"containsRomType",
			new String[] { Long.class.getName(), Long.class.getName() });

	/**
	 * Returns <code>true</code> if the rom type is associated with the hotel.
	 *
	 * @param pk the primary key of the hotel
	 * @param romTypePK the primary key of the rom type
	 * @return <code>true</code> if the rom type is associated with the hotel; <code>false</code> otherwise
	 * @throws SystemException if a system exception occurred
	 */
	public boolean containsRomType(long pk, long romTypePK)
		throws SystemException {
		Object[] finderArgs = new Object[] { pk, romTypePK };

		Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ROMTYPE,
				finderArgs, this);

		if (value == null) {
			try {
				value = Boolean.valueOf(containsRomType.contains(pk, romTypePK));
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (value == null) {
					value = Boolean.FALSE;
				}

				FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ROMTYPE,
					finderArgs, value);
			}
		}

		return value.booleanValue();
	}

	/**
	 * Returns <code>true</code> if the hotel has any rom types associated with it.
	 *
	 * @param pk the primary key of the hotel to check for associations with rom types
	 * @return <code>true</code> if the hotel has any rom types associated with it; <code>false</code> otherwise
	 * @throws SystemException if a system exception occurred
	 */
	public boolean containsRomTypes(long pk) throws SystemException {
		if (getRomTypesSize(pk) > 0) {
			return true;
		}
		else {
			return false;
		}
	}

	/**
	 * Returns all the tbl comments associated with the hotel.
	 *
	 * @param pk the primary key of the hotel
	 * @return the tbl comments associated with the hotel
	 * @throws SystemException if a system exception occurred
	 */
	public List<com.hotel.test.model.TblComment> getTblComments(long pk)
		throws SystemException {
		return getTblComments(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
	}

	/**
	 * Returns a range of all the tbl comments associated with the hotel.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param pk the primary key of the hotel
	 * @param start the lower bound of the range of hotels
	 * @param end the upper bound of the range of hotels (not inclusive)
	 * @return the range of tbl comments associated with the hotel
	 * @throws SystemException if a system exception occurred
	 */
	public List<com.hotel.test.model.TblComment> getTblComments(long pk,
		int start, int end) throws SystemException {
		return getTblComments(pk, start, end, null);
	}

	public static final FinderPath FINDER_PATH_GET_TBLCOMMENTS = new FinderPath(com.hotel.test.model.impl.TblCommentModelImpl.ENTITY_CACHE_ENABLED,
			com.hotel.test.model.impl.TblCommentModelImpl.FINDER_CACHE_ENABLED,
			com.hotel.test.model.impl.TblCommentImpl.class,
			com.hotel.test.service.persistence.TblCommentPersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"getTblComments",
			new String[] {
				Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});

	/**
	 * Returns an ordered range of all the tbl comments associated with the hotel.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param pk the primary key of the hotel
	 * @param start the lower bound of the range of hotels
	 * @param end the upper bound of the range of hotels (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of tbl comments associated with the hotel
	 * @throws SystemException if a system exception occurred
	 */
	public List<com.hotel.test.model.TblComment> getTblComments(long pk,
		int start, int end, OrderByComparator orderByComparator)
		throws SystemException {
		Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };

		List<com.hotel.test.model.TblComment> list = (List<com.hotel.test.model.TblComment>)FinderCacheUtil.getResult(FINDER_PATH_GET_TBLCOMMENTS,
				finderArgs, this);

		if (list == null) {
			Session session = null;

			try {
				session = openSession();

				String sql = null;

				if (orderByComparator != null) {
					sql = _SQL_GETTBLCOMMENTS.concat(ORDER_BY_CLAUSE)
											 .concat(orderByComparator.getOrderBy());
				}
				else {
					sql = _SQL_GETTBLCOMMENTS.concat(com.hotel.test.model.impl.TblCommentModelImpl.ORDER_BY_SQL);
				}

				SQLQuery q = session.createSQLQuery(sql);

				q.addEntity("HT_TblComment",
					com.hotel.test.model.impl.TblCommentImpl.class);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(pk);

				list = (List<com.hotel.test.model.TblComment>)QueryUtil.list(q,
						getDialect(), start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_GET_TBLCOMMENTS,
						finderArgs);
				}
				else {
					tblCommentPersistence.cacheResult(list);

					FinderCacheUtil.putResult(FINDER_PATH_GET_TBLCOMMENTS,
						finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	public static final FinderPath FINDER_PATH_GET_TBLCOMMENTS_SIZE = new FinderPath(com.hotel.test.model.impl.TblCommentModelImpl.ENTITY_CACHE_ENABLED,
			com.hotel.test.model.impl.TblCommentModelImpl.FINDER_CACHE_ENABLED,
			com.hotel.test.model.impl.TblCommentImpl.class,
			com.hotel.test.service.persistence.TblCommentPersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"getTblCommentsSize", new String[] { Long.class.getName() });

	/**
	 * Returns the number of tbl comments associated with the hotel.
	 *
	 * @param pk the primary key of the hotel
	 * @return the number of tbl comments associated with the hotel
	 * @throws SystemException if a system exception occurred
	 */
	public int getTblCommentsSize(long pk) throws SystemException {
		Object[] finderArgs = new Object[] { pk };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_TBLCOMMENTS_SIZE,
				finderArgs, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				SQLQuery q = session.createSQLQuery(_SQL_GETTBLCOMMENTSSIZE);

				q.addScalar(COUNT_COLUMN_NAME,
					com.liferay.portal.kernel.dao.orm.Type.LONG);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(pk);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_GET_TBLCOMMENTS_SIZE,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	public static final FinderPath FINDER_PATH_CONTAINS_TBLCOMMENT = new FinderPath(com.hotel.test.model.impl.TblCommentModelImpl.ENTITY_CACHE_ENABLED,
			com.hotel.test.model.impl.TblCommentModelImpl.FINDER_CACHE_ENABLED,
			com.hotel.test.model.impl.TblCommentImpl.class,
			com.hotel.test.service.persistence.TblCommentPersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"containsTblComment",
			new String[] { Long.class.getName(), Long.class.getName() });

	/**
	 * Returns <code>true</code> if the tbl comment is associated with the hotel.
	 *
	 * @param pk the primary key of the hotel
	 * @param tblCommentPK the primary key of the tbl comment
	 * @return <code>true</code> if the tbl comment is associated with the hotel; <code>false</code> otherwise
	 * @throws SystemException if a system exception occurred
	 */
	public boolean containsTblComment(long pk, long tblCommentPK)
		throws SystemException {
		Object[] finderArgs = new Object[] { pk, tblCommentPK };

		Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_TBLCOMMENT,
				finderArgs, this);

		if (value == null) {
			try {
				value = Boolean.valueOf(containsTblComment.contains(pk,
							tblCommentPK));
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (value == null) {
					value = Boolean.FALSE;
				}

				FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_TBLCOMMENT,
					finderArgs, value);
			}
		}

		return value.booleanValue();
	}

	/**
	 * Returns <code>true</code> if the hotel has any tbl comments associated with it.
	 *
	 * @param pk the primary key of the hotel to check for associations with tbl comments
	 * @return <code>true</code> if the hotel has any tbl comments associated with it; <code>false</code> otherwise
	 * @throws SystemException if a system exception occurred
	 */
	public boolean containsTblComments(long pk) throws SystemException {
		if (getTblCommentsSize(pk) > 0) {
			return true;
		}
		else {
			return false;
		}
	}

	/**
	 * Returns all the bookings associated with the hotel.
	 *
	 * @param pk the primary key of the hotel
	 * @return the bookings associated with the hotel
	 * @throws SystemException if a system exception occurred
	 */
	public List<com.hotel.test.model.Booking> getBookings(long pk)
		throws SystemException {
		return getBookings(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
	}

	/**
	 * Returns a range of all the bookings associated with the hotel.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param pk the primary key of the hotel
	 * @param start the lower bound of the range of hotels
	 * @param end the upper bound of the range of hotels (not inclusive)
	 * @return the range of bookings associated with the hotel
	 * @throws SystemException if a system exception occurred
	 */
	public List<com.hotel.test.model.Booking> getBookings(long pk, int start,
		int end) throws SystemException {
		return getBookings(pk, start, end, null);
	}

	public static final FinderPath FINDER_PATH_GET_BOOKINGS = new FinderPath(com.hotel.test.model.impl.BookingModelImpl.ENTITY_CACHE_ENABLED,
			com.hotel.test.model.impl.BookingModelImpl.FINDER_CACHE_ENABLED,
			com.hotel.test.model.impl.BookingImpl.class,
			com.hotel.test.service.persistence.BookingPersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"getBookings",
			new String[] {
				Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});

	/**
	 * Returns an ordered range of all the bookings associated with the hotel.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param pk the primary key of the hotel
	 * @param start the lower bound of the range of hotels
	 * @param end the upper bound of the range of hotels (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of bookings associated with the hotel
	 * @throws SystemException if a system exception occurred
	 */
	public List<com.hotel.test.model.Booking> getBookings(long pk, int start,
		int end, OrderByComparator orderByComparator) throws SystemException {
		Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };

		List<com.hotel.test.model.Booking> list = (List<com.hotel.test.model.Booking>)FinderCacheUtil.getResult(FINDER_PATH_GET_BOOKINGS,
				finderArgs, this);

		if (list == null) {
			Session session = null;

			try {
				session = openSession();

				String sql = null;

				if (orderByComparator != null) {
					sql = _SQL_GETBOOKINGS.concat(ORDER_BY_CLAUSE)
										  .concat(orderByComparator.getOrderBy());
				}
				else {
					sql = _SQL_GETBOOKINGS.concat(com.hotel.test.model.impl.BookingModelImpl.ORDER_BY_SQL);
				}

				SQLQuery q = session.createSQLQuery(sql);

				q.addEntity("HT_Booking",
					com.hotel.test.model.impl.BookingImpl.class);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(pk);

				list = (List<com.hotel.test.model.Booking>)QueryUtil.list(q,
						getDialect(), start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_GET_BOOKINGS,
						finderArgs);
				}
				else {
					bookingPersistence.cacheResult(list);

					FinderCacheUtil.putResult(FINDER_PATH_GET_BOOKINGS,
						finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	public static final FinderPath FINDER_PATH_GET_BOOKINGS_SIZE = new FinderPath(com.hotel.test.model.impl.BookingModelImpl.ENTITY_CACHE_ENABLED,
			com.hotel.test.model.impl.BookingModelImpl.FINDER_CACHE_ENABLED,
			com.hotel.test.model.impl.BookingImpl.class,
			com.hotel.test.service.persistence.BookingPersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"getBookingsSize", new String[] { Long.class.getName() });

	/**
	 * Returns the number of bookings associated with the hotel.
	 *
	 * @param pk the primary key of the hotel
	 * @return the number of bookings associated with the hotel
	 * @throws SystemException if a system exception occurred
	 */
	public int getBookingsSize(long pk) throws SystemException {
		Object[] finderArgs = new Object[] { pk };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_BOOKINGS_SIZE,
				finderArgs, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				SQLQuery q = session.createSQLQuery(_SQL_GETBOOKINGSSIZE);

				q.addScalar(COUNT_COLUMN_NAME,
					com.liferay.portal.kernel.dao.orm.Type.LONG);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(pk);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_GET_BOOKINGS_SIZE,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	public static final FinderPath FINDER_PATH_CONTAINS_BOOKING = new FinderPath(com.hotel.test.model.impl.BookingModelImpl.ENTITY_CACHE_ENABLED,
			com.hotel.test.model.impl.BookingModelImpl.FINDER_CACHE_ENABLED,
			com.hotel.test.model.impl.BookingImpl.class,
			com.hotel.test.service.persistence.BookingPersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"containsBooking",
			new String[] { Long.class.getName(), Long.class.getName() });

	/**
	 * Returns <code>true</code> if the booking is associated with the hotel.
	 *
	 * @param pk the primary key of the hotel
	 * @param bookingPK the primary key of the booking
	 * @return <code>true</code> if the booking is associated with the hotel; <code>false</code> otherwise
	 * @throws SystemException if a system exception occurred
	 */
	public boolean containsBooking(long pk, long bookingPK)
		throws SystemException {
		Object[] finderArgs = new Object[] { pk, bookingPK };

		Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_BOOKING,
				finderArgs, this);

		if (value == null) {
			try {
				value = Boolean.valueOf(containsBooking.contains(pk, bookingPK));
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (value == null) {
					value = Boolean.FALSE;
				}

				FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_BOOKING,
					finderArgs, value);
			}
		}

		return value.booleanValue();
	}

	/**
	 * Returns <code>true</code> if the hotel has any bookings associated with it.
	 *
	 * @param pk the primary key of the hotel to check for associations with bookings
	 * @return <code>true</code> if the hotel has any bookings associated with it; <code>false</code> otherwise
	 * @throws SystemException if a system exception occurred
	 */
	public boolean containsBookings(long pk) throws SystemException {
		if (getBookingsSize(pk) > 0) {
			return true;
		}
		else {
			return false;
		}
	}

	/**
	 * Initializes the hotel persistence.
	 */
	public void afterPropertiesSet() {
		String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
					com.liferay.util.service.ServiceProps.get(
						"value.object.listener.com.hotel.test.model.Hotel")));

		if (listenerClassNames.length > 0) {
			try {
				List<ModelListener<Hotel>> listenersList = new ArrayList<ModelListener<Hotel>>();

				for (String listenerClassName : listenerClassNames) {
					listenersList.add((ModelListener<Hotel>)InstanceFactory.newInstance(
							listenerClassName));
				}

				listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
			}
			catch (Exception e) {
				_log.error(e);
			}
		}

		containsRomType = new ContainsRomType();

		containsTblComment = new ContainsTblComment();

		containsBooking = new ContainsBooking();
	}

	public void destroy() {
		EntityCacheUtil.removeCache(HotelImpl.class.getName());
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	@BeanReference(type = BookingPersistence.class)
	protected BookingPersistence bookingPersistence;
	@BeanReference(type = HotelPersistence.class)
	protected HotelPersistence hotelPersistence;
	@BeanReference(type = LocalPersistence.class)
	protected LocalPersistence localPersistence;
	@BeanReference(type = RomTypePersistence.class)
	protected RomTypePersistence romTypePersistence;
	@BeanReference(type = TblCommentPersistence.class)
	protected TblCommentPersistence tblCommentPersistence;
	@BeanReference(type = ResourcePersistence.class)
	protected ResourcePersistence resourcePersistence;
	@BeanReference(type = UserPersistence.class)
	protected UserPersistence userPersistence;
	protected ContainsRomType containsRomType;
	protected ContainsTblComment containsTblComment;
	protected ContainsBooking containsBooking;

	protected class ContainsRomType {
		protected ContainsRomType() {
			_mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
					_SQL_CONTAINSROMTYPE,
					new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
					RowMapper.COUNT);
		}

		protected boolean contains(long hotelId, long romId) {
			List<Integer> results = _mappingSqlQuery.execute(new Object[] {
						new Long(hotelId), new Long(romId)
					});

			if (results.size() > 0) {
				Integer count = results.get(0);

				if (count.intValue() > 0) {
					return true;
				}
			}

			return false;
		}

		private MappingSqlQuery<Integer> _mappingSqlQuery;
	}

	protected class ContainsTblComment {
		protected ContainsTblComment() {
			_mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
					_SQL_CONTAINSTBLCOMMENT,
					new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
					RowMapper.COUNT);
		}

		protected boolean contains(long hotelId, long commentId) {
			List<Integer> results = _mappingSqlQuery.execute(new Object[] {
						new Long(hotelId), new Long(commentId)
					});

			if (results.size() > 0) {
				Integer count = results.get(0);

				if (count.intValue() > 0) {
					return true;
				}
			}

			return false;
		}

		private MappingSqlQuery<Integer> _mappingSqlQuery;
	}

	protected class ContainsBooking {
		protected ContainsBooking() {
			_mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
					_SQL_CONTAINSBOOKING,
					new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
					RowMapper.COUNT);
		}

		protected boolean contains(long hotelId, long bookId) {
			List<Integer> results = _mappingSqlQuery.execute(new Object[] {
						new Long(hotelId), new Long(bookId)
					});

			if (results.size() > 0) {
				Integer count = results.get(0);

				if (count.intValue() > 0) {
					return true;
				}
			}

			return false;
		}

		private MappingSqlQuery<Integer> _mappingSqlQuery;
	}

	private static final String _SQL_SELECT_HOTEL = "SELECT hotel FROM Hotel hotel";
	private static final String _SQL_SELECT_HOTEL_WHERE = "SELECT hotel FROM Hotel hotel WHERE ";
	private static final String _SQL_COUNT_HOTEL = "SELECT COUNT(hotel) FROM Hotel hotel";
	private static final String _SQL_COUNT_HOTEL_WHERE = "SELECT COUNT(hotel) FROM Hotel hotel WHERE ";
	private static final String _SQL_GETROMTYPES = "SELECT {HT_RomType.*} FROM HT_RomType INNER JOIN HT_Hotel ON (HT_Hotel.hotelId = HT_RomType.hotelId) WHERE (HT_Hotel.hotelId = ?)";
	private static final String _SQL_GETROMTYPESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM HT_RomType WHERE hotelId = ?";
	private static final String _SQL_CONTAINSROMTYPE = "SELECT COUNT(*) AS COUNT_VALUE FROM HT_RomType WHERE hotelId = ? AND romId = ?";
	private static final String _SQL_GETTBLCOMMENTS = "SELECT {HT_TblComment.*} FROM HT_TblComment INNER JOIN HT_Hotel ON (HT_Hotel.hotelId = HT_TblComment.hotelId) WHERE (HT_Hotel.hotelId = ?)";
	private static final String _SQL_GETTBLCOMMENTSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM HT_TblComment WHERE hotelId = ?";
	private static final String _SQL_CONTAINSTBLCOMMENT = "SELECT COUNT(*) AS COUNT_VALUE FROM HT_TblComment WHERE hotelId = ? AND commentId = ?";
	private static final String _SQL_GETBOOKINGS = "SELECT {HT_Booking.*} FROM HT_Booking INNER JOIN HT_Hotel ON (HT_Hotel.hotelId = HT_Booking.hotelId) WHERE (HT_Hotel.hotelId = ?)";
	private static final String _SQL_GETBOOKINGSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM HT_Booking WHERE hotelId = ?";
	private static final String _SQL_CONTAINSBOOKING = "SELECT COUNT(*) AS COUNT_VALUE FROM HT_Booking WHERE hotelId = ? AND bookId = ?";
	private static final String _FINDER_COLUMN_HOTELNAME_HOTELNAME_1 = "hotel.hotelName IS NULL";
	private static final String _FINDER_COLUMN_HOTELNAME_HOTELNAME_2 = "hotel.hotelName = ?";
	private static final String _FINDER_COLUMN_HOTELNAME_HOTELNAME_3 = "(hotel.hotelName IS NULL OR hotel.hotelName = ?)";
	private static final String _ORDER_BY_ENTITY_ALIAS = "hotel.";
	private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Hotel exists with the primary key ";
	private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Hotel exists with the key {";
	private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
				PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
	private static Log _log = LogFactoryUtil.getLog(HotelPersistenceImpl.class);
	private static Hotel _nullHotel = new HotelImpl() {
			@Override
			public Object clone() {
				return this;
			}

			@Override
			public CacheModel<Hotel> toCacheModel() {
				return _nullHotelCacheModel;
			}
		};

	private static CacheModel<Hotel> _nullHotelCacheModel = new CacheModel<Hotel>() {
			public Hotel toEntityModel() {
				return _nullHotel;
			}
		};
}